﻿using Server.Constant;
using Server.Framework.Message;
using Server.Model;
using System.Collections.Generic;

namespace Server.Message.Request
{
    /// <summary>
    /// Author: Leil
    /// Description: 新增或编辑请求消息
    /// CreateTime: 2020/5/13 10:07:46
    /// </summary>
    [MessageAttr(MessageId.ADD_EDIT_USER)]
    class AddEditUserReq : RequestBaseMessage
    {
        public UserDao UserDao { get; private set; }

        public List<int> RoleIds { get; private set; } = new List<int>();

        public override void Deserialize(byte[] buffer)
        {
            AddEditUser msg = AddEditUser.Parser.ParseFrom(buffer);
            if (msg.User != null)
            {
                UserDao = new UserDao
                {
                    ID = msg.User.Id,
                    OrgId = msg.User.OrgId,
                    LoginName = msg.User.LoginName,
                    Password = msg.User.Password,
                    Status = msg.User.Status,
                    Sort = msg.User.Sort,
                };
            }
            RoleIds.AddRange(msg.User.RoleIds);
        }
    }
}
